<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            margin: 100px auto;
            width: 200px;
            height: 20px;
            border: 1px solid pink;
        }

        @keyframes identifier {
            0% {
                width: 0;
            }

            100% {
                width: 200px;
            }
        }

        .box div {
            height: 20px;
            background-color: pink;
            animation-name: identifier;
            animation-duration: 6s;
            animation-iteration-count: infinite;
            animation-direction: alternate;
        }

        .box .content span {
            position: absolute;
            right: 0;
            top: 0;
            margin-right: -35px;
            font-size: 12px;
            font-weight: bold;
            color: black;
            line-height: 20px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="content">
            <span>100%</span>
        </div>
    </div>
    <script>
        var box = document.querySelector(".box")
        var div = document.querySelector(".box div")
        var span = document.querySelector(".box span")
        var timer = setInterval(function () {
            var width = div.offsetWidth
            if (width >= 200) {
                // clearInterval(timer)
            }
            span.innerHTML = parseInt(width / 2) + "%"
        }, 100);
    </script>
</body>

</html>